package es.seam.myebay.model;

import java.sql.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;

@Name("auction")
@Entity
public class Auction {

    private int id;
    private Date endDate;
    private double startingPrice;
    private Account owner;
    private Item item;
    private List<Bid> bids;
    private Bid highBid;
    
   
    @Id
    @GeneratedValue
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    
    @NotNull
    @ManyToOne
    @JoinColumn(name="id_account")
    public Account getAccount() {
        return owner;
    }
    public void setAccount(Account account) {
        this.owner = account;
    }
    
    
    @NotNull
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "id_item")
    public Item getItem() {
        return item;
    }
    public void setItem(Item item) {
        this.item = item;
    }
    
    
    @NotNull
    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="auction")
    public List<Bid> getBids() {
        return bids;
    }
    public void setBids(List<Bid> bids) {
        this.bids = bids;
    }

    @Column(name="end_date")
    public Date getEndDate() {
        return endDate;
    }
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
    
    @NotNull
    @Column(name="starting_price")
    public double getStartingPrice() {
        return startingPrice;
    }
    public void setStartingPrice(double startingPrice) {
        this.startingPrice = startingPrice;
    }

    @Transient
    public Bid getHighBid() {
        return highBid;
    }
    public void setHighBid(Bid highBid) {
        this.highBid = highBid;
    }
}
